// topologyTree.h: Build R-tree structure for fast search.
//
//////////////////////////////////////////////////////////////////////

#ifndef AM_TREE_TOPOLOGY
#define AM_TREE_TOPOLOGY

#include "topology.hpp"

//
//////////////////////////////////////////////////////////////////////////
class topologyTree
{
public:
  topologyTree(void);
  ~topologyTree(void);

  // input - set current mesh to build trees
  void setMesh (cTopology *mesh);

  // input - build trees
  void buildNodeTree (double box);
  void buildElemTree ( );
  void buildEdgeTree ( );

  // output => searchers
  vector <int> findNodes (double xmin, double ymin, double zmin,
                          double xmax, double ymax, double zmax);
  vector <int> findElems (double xmin, double ymin, double zmin,
                          double xmax, double ymax, double zmax);
  vector <int> findEdges (double xmin, double ymin, double zmin,
                          double xmax, double ymax, double zmax);

  void *getNodeTree ( ) { return m_nodeTree; }
  void *getElemTree ( ) { return m_elemTree; }
  void *getEdgeTree ( ) { return m_edgeTree; }

private:

  // trees
  void *m_nodeTree;
  void *m_elemTree;
  void *m_edgeTree;

  // id vectors used to set pointer to trees
  int *m_nodeIds;
  int *m_elemIds;
  int *m_edgeIds;

  // curr mesh
  cTopology *m_mesh;

  double xmin, ymin, zmin, xmax, ymax, zmax;

  vector <int> find (void *tree, double xmin, double ymin, double zmin,
    double xmax, double ymax, double zmax);

};

#endif